package net.tavion.angelboot.common.utils;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ObjectMapperUtils {

    private static final Logger logger = LoggerFactory.getLogger(ObjectMapperUtils.class);

    public static <T> T readToObject(String content, Class<T> valueType, ObjectMapper objectMapper) {
        if (StringUtils.isBlank(content)) {
            return null;
        } else {
            try {
                return objectMapper.readValue(content, valueType);
            } catch (Exception var4) {
                logger.error(var4.getMessage(),var4);
                return null;
            }
        }
    }

    public static <T> String writeAsString(T object, ObjectMapper objectMapper) {
        try {
            return objectMapper.writeValueAsString(object);
        } catch (Exception var3) {
            logger.error(var3.getMessage(),var3);
            return null;
        }
    }


    public static <T> byte[] writeValueAsBytes(T object, ObjectMapper objectMapper) {
        try {
            return objectMapper.writeValueAsBytes(object);
        } catch (Exception var3) {
            logger.error(var3.getMessage(),var3);
            return null;
        }
    }
}
